define(['angular'], function (angular) {
    "use strict";

    var factory = function ($ionicPopup, CommonService, VIDEO_PATH) {
        return {
            asyncVideo: function (params, callback) {
                //检查网络状态
                tf.networkStatus.getConnectionInfo(function (data) {
                    var network = data.connectionInfo;
                    // 如果网络是2G，给出提示
                    if (network == "2" || network == "9") {
                        CommonService.showAlert({message: '你当前使用的网络网速较慢，请在3G,4G或者wifi等网路状态下进行视频见证'});
                    } else {
                        //开始视频见证
                        tf.video.start({
                            businessNumber: params.businessNumber,
                            isSingle: '2',
                            clientId: params.user_id,
                            clientName: params.client_name,
                            orgId: params.branch_no,
                            jsessionId: '1',
                            busUrl: VIDEO_PATH + '/servlet/json'
                        }, function (data) {
                            callback(data);
                        });
                    }
                });
            },
            showSelectDevice: function (event) {
                $ionicPopup.show({
                    cssClass: "vDialog",
                    template: '',
                    title: '请选择源',
                    buttons: [{
                        text: '<i class="icon ion-camera energized"></i>',
                        type: 'button button-icon',
                        onTap: function () {
                            tf.camera.takePicture({
                                targetType: '1',
                                mediaType: '1',
                                photoType: '1'
                            }, event);
                        }
                    }, {
                        text: '<i class="icon ion-images energized"></i>',
                        type: 'button button-icon',
                        onTap: function () {
                            tf.camera.takePicture({
                                targetType: '1',
                                mediaType: '2',
                                photoType: '3'
                            }, event);
                        }
                    }, {
                        text: '<i class="icon ion-log-out dark"></i>',
                        type: 'button',
                        onTap: function () {

                        }
                    }]
                });
            }
        }
    };

    factory.$inject = ['$ionicPopup', 'CommonService', 'VIDEO_PATH'];
    return factory;
});